package cn.jobstart.controller;

import cn.jobstart.dto.AdminJobDTO;
import cn.jobstart.dto.AdminJobModManagerDTO;
import cn.jobstart.dto.AdminJobPageDTO;
import cn.jobstart.export.AdminJobDomainExport;
import cn.jobstart.modelExt.AdminJobExt;
import cn.jobstart.pubInter.IBaseService;
import cn.jobstart.pubInter.aop.SystemLog;
import cn.jobstart.pubInter.exception.SkException;
import cn.jobstart.searchExt.AdminJobSearchExt;
import cn.jobstart.service.IAdminJobService;
import cn.jobstart.vo.AdminJobDetailDomainVO;
import cn.jobstart.vo.AdminJobDetailVO;
import cn.jobstart.vo.AdminJobDomainVO;
import cn.jobstart.vo.AdminJobListVO;
import cn.jobstart.web.common.SkJsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashSet;
import java.util.Set;

/**
 * @author sunke
 * @Date 2023-09-06 15:00:20
 * @description AdminJobController      员工职位
 */
@Api(tags = "人才管理系统-员工职位相关", description = "员工职位相关接口")
@RestController(value = "adminJobRestfulController")
@RequestMapping("/adminJob/")
@Validated
public class AdminJobController extends ApiManageController<AdminJobDTO, AdminJobPageDTO, AdminJobExt, AdminJobSearchExt, AdminJobDomainVO, AdminJobDetailDomainVO, AdminJobDetailVO, AdminJobListVO, String> {

    @Resource(name = "adminJobService")
    private IAdminJobService adminJobService;


    @ApiOperation(value = "我的职位列表", notes = "我的职位列表")
    @PostMapping(value = "myJobList")
    public SkJsonResult<AdminJobListVO> myJobList(@RequestBody AdminJobPageDTO pageDTO, HttpServletRequest request, HttpSession session) throws SkException {
        pageDTO.setAdminIdEq(getJwtsUtil().getAdminId(request));
        return super.list(pageDTO, request, session);
    }

    @ApiOperation(value = "修改负责人", notes = "修改负责人", httpMethod = "POST")
    @PostMapping("modManagerAction")
    @SystemLog(title = "修改负责人", businessType = 1, method = "modManagerAction")
    public SkJsonResult modManagerAction(@RequestBody AdminJobModManagerDTO dto, HttpServletRequest request, HttpSession session) throws SkException {


        adminJobService.modManager(dto.getAdminJobId(), dto.getAdminIds(), getJwtsUtil().getAdminId(request), getJwtsUtil().getAdminTruename(request));


        return SkJsonResult.ok();

        //	return super.postAdd(dto, request, session);
    }


    @Override
    public boolean beforePostAdd(AdminJobDTO dto, AdminJobExt domain, HttpServletRequest request, HttpSession session) throws SkException {

        domain.setAdminId(getJwtsUtil().getAdminId(request));
        domain.setAdminTruename(getJwtsUtil().getAdminTruename(request));

        return super.beforePostAdd(dto, domain, request, session);
    }

    @Override
    public IBaseService<AdminJobExt, AdminJobSearchExt, String> getBaseService() throws SkException {
        return adminJobService;
    }

    @Override
    public String getBaseRoute() {
        return "/adminJob/";
    }

    /**
     * 当前模板名称
     *
     * @return
     */
    @Override
    public String getModelName() {
        return "员工职位";
    }

    @Override
    public Class exportExcelClass() {
        return AdminJobDomainExport.class;
    }

    @Override
    public Set<String> totalMapSet() {
        Set totalMapSet = new HashSet();
        totalMapSet.add("count(admin_job.aj_id) as countNum");
        return totalMapSet;
    }


}